Note: This tutorial assumes that you have completed the previous tutorials: Installation - ROS Development Environment. |
Please ask about problems and questions regarding this tutorial on answers.ros.org. Don't forget to include in your question the link to this page, the versions of your OS & ROS, and also add appropriate tags. |
Creating Android Packages
Description: Script wizards for conveniently creating android packages and projects.Keywords: rosjava android
Tutorial Level: BEGINNER
Overview
Use the catkin_create_rosjava_xx scripts to populate android packages and subprojects.
Note that your source repository for a new android studio/sdk workspace is simply a gradle multi-project workspace. Here we set up the package with the root gradle multi-project configuration with minimal catkin information (via package.xml), and the actual android project(s) underneath this.
Preparation
You will need a ros environment for your android installation to utilise these scripts.
Package Creation
Create an empty workspace and populate it with many gradle files!
> mkdir -p android/src > cd android/src > catkin_create_android_pkg android_foo android_apps android_extras rosjava_core > cd android_foo > catkin_create_android_project -s 10 -p com.github.ros_java.android_foo.bar bar > catkin_create_android_library_project -s 13 -p com.github.ros_java.android_foo.barlib barlib > cd ../.. > catkin_make
Be sure to choose a unique package name and set an appropriate sdk version for your app.
Adding Dependencies
Each individual android subproject's build.gradle file needs to be populated with the dependencies you need for your application.
Dependencies to subprojects in the same android_foo package can be added to bar's build.gradle:
... dependencies { //add dependency linking to subproject barlib compile project(':barlib') } ...
Dependencies on an external Maven repository, particularly useful if you've created a 'Diet Workspace' as discussed in ros environment, can be added to bar and barlib's build.gradle:
... repositories { maven { url 'https://github.com/rosjava/rosjava_mvn_repo/raw/master' } mavenCentral() } dependencies { //add dependency linking to the core android and rosjava libraries compile 'org.ros.android_core:android_gingerbread_mr1:0.1.+' compile 'org.ros.android_core:android_honeycomb_mr2:0.1.+' compile 'org.ros.rosjava_core:rosjava:0.1.+' } ...
Using Custom Messages
Custom message dependencies can be added to your android package by first defining the custom message package foo_msgs as described in Creating Msg and Srv. You can then use the catkin_create_rosjava_msg_project foo_msgs command as described in the rosjava custom message tutorial.
You can create your foo_msgs stand-in rosjava subproject directly inside the android_foo package, however you will have to modify the top-level build.gradle to apply the appropriate plugins during compilation:
Replace:
subprojects { apply plugin: 'ros-android' }
with
subprojects { if (name.contains('docs')){ //do nothing }else if (name.contains('msgs')) { apply plugin: 'ros-java' }else{ apply plugin: 'ros-android' } }
And finally, don't forget to add compile project(':foo_msgs') as a dependency to each subproject's build.gradle.